package edu.zut.cs.software.perfect.student.service.impl;

import java.util.List;
import java.util.Optional;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.zut.cs.software.perfect.base.service.impl.GenericManagerImpl;
import edu.zut.cs.software.perfect.student.dao.StudentDao;
import edu.zut.cs.software.perfect.student.domain.Student;
import edu.zut.cs.software.perfect.student.service.StudentManager;
/**
 * @ClassName StudentManagerImpl
 * @Description TODO
 * @Author jihao
 * @Date 2020年3月20日 下午1:25:33
 * @Version 1.0
 */
@Service("studentManager")
@Transactional
public class StudentManagerImpl extends GenericManagerImpl<Long, Student> implements StudentManager {

	StudentDao studentdao;
	@Autowired
	public void setStudentdao(StudentDao studentdao) {
		this.studentdao = studentdao;
		this.dao=this.studentdao;
	}

	@Override
	public Student echo(Student stu) {
		stu.setName("ji");
		stu.setGrade("99");
		return stu;
	}

	@Override
	public List<Student> findAll() {
		return (List<Student>) this.dao.findAll();
	}
	@Override
	public Optional<Student> findByCourseId(Long courseId) {
		// TODO Auto-generated method stub
		Optional<Student> result = this.dao.findById(courseId);
		return result;
	}
	
	@Override
	public Boolean deleteStudentId(Long courseId) {
		// TODO Auto-generated method stub
		//为空返回Optional.empty()
		Optional<Student> student = this.dao.findById(courseId);
		if(student.equals(Optional.empty())) {
			return false;
		}else {
			this.dao.delete(student.get());
			return true;
		}
	}

	@Override
	public Student findByName(String name) {
		// TODO Auto-generated method stub
		return null;
	}
}
